package com.example.ccjml;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.annotation.Nullable;

import com.example.ccj.b.a.BaseActivity;
import com.example.ccj.b.a.LocationMapActivity;
import com.example.ccj.b.a.OneMarkerLocation;
import com.example.ccj.b.a.ScanCodeActivity;
import com.example.ccj.b.c.custom.MButton;
import com.example.ccj.b.c.custom.image.MLocalMedia;
import com.example.ccj.b.c.custom.selectuser.ISelectUserListener;
import com.example.ccj.b.c.custom.selectuser.OnlySelectUserDialog;
import com.example.ccj.b.c.custom.selectuser.UserMode;
import com.example.ccj.b.c.custom.tree.ISelectTreeListener;
import com.example.ccj.b.c.custom.tree.TreeMode;
import com.example.ccj.b.c.custom.tree.TreeView;
import com.example.ccj.b.c.custom.tree.tree2.TreeStructure2;
import com.example.ccj.b.c.dialogfragment.scancode.IScanCodeListener;
import com.example.ccj.b.c.dialogfragment.scancode.ScanCodeDialogFragment;
import com.example.ccj.b.c.dialogxy.impl.DialogTest;
import com.example.ccj.b.c.recycler.BaseRecycler;
import com.example.ccj.u.DeviceUtils;
import com.example.ccj.u.LogUtils;
import com.example.ccj.u.NumberUtils;
import com.example.ccj.u.ToastUtils;
import com.example.ccj.u.map.LocationListener;
import com.example.ccj.u.map.LocationMode;
import com.example.ccj.u.map.LocationUtil;
import com.example.ccj.u.media.IPictureSelectResultListener;
import com.example.ccj.u.media.IPictureSelectResultListener2;
import com.example.ccj.u.media.MediaUtils;
import com.example.ccj.u.power.PowerPer;
import com.example.ccjml.ui.theme.TestFenShuActivity;
import com.luck.picture.lib.entity.LocalMedia;

import java.util.ArrayList;
import java.util.List;

public class MainActivity2 extends BaseActivity {

    MButton testAddImage,testOptionChoice,testNavigationPage,textfenshu,selectPerson,tree,tree2,map,one_marker,getOneLocation,
            getAllLocation,scan,scanDialog,uploadCos,showBigPicture,filePick,loadImage;

    ScanCodeDialogFragment fragment;
    @Override
    protected boolean isFull() {
        return false;
    }


    @Override
    public void initData(@Nullable Bundle bundle) {
        testAddImage.setOnClickListener(v->jump(TestAddImageActivity.class));
        testOptionChoice.setOnClickListener(v->jump(TestOptionChoiceControl.class));
        testNavigationPage.setOnClickListener(v->jump(TestNavigationPageActivity.class));
        textfenshu.setOnClickListener(v->jump(TestFenShuActivity.class));
        LogUtils.e("initData");

        //获取地图权限
        PowerPer.getMultiPermission(this,259, android.Manifest.permission.ACCESS_COARSE_LOCATION,
                android.Manifest.permission.ACCESS_FINE_LOCATION);
    }

    @Override
    public void initView(@Nullable Bundle savedInstanceState, @Nullable View contentView) {
        testAddImage = findViewById(R.id.activity_main_test_add_image);
        testOptionChoice = findViewById(R.id.activity_main_test_option_choice);
        testNavigationPage = findViewById(R.id.activity_main_test_navigation_page);
        textfenshu = findViewById(R.id.activity_main_test_fenshu);
        selectPerson = findViewById(R.id.activity_main_test_select_person);
        tree = findViewById(R.id.activity_main_test_tree);
        tree2 = findViewById(R.id.activity_main_test_tree3);
        map = findViewById(R.id.activity_main_test_map);
        one_marker = findViewById(R.id.activity_main_test_map_one_marker);
        getOneLocation = findViewById(R.id.activity_main_test_map_get_one_location);
        getAllLocation = findViewById(R.id.activity_main_test_map_get_all_location);
        scan = findViewById(R.id.activity_main_test_map_scan);
        scanDialog = findViewById(R.id.activity_main_test_map_scan_dialog);
        uploadCos = findViewById(R.id.activity_main_test_select_img_upload);
        showBigPicture = findViewById(R.id.activity_main_test_big_picture);
        filePick = findViewById(R.id.activity_main_test_file_pick);
        loadImage = findViewById(R.id.activity_main_test_load_image);



        loadImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogTest test = new DialogTest(v.getContext());
                test.show();
            }
        });


        filePick.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity2.this, FilePickActivity.class);
                startActivity(intent);
            }
        });


        List<MLocalMedia> myImageList = new ArrayList<>();

        showBigPicture.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(MainActivity2.this, TestMapActivity.class);
                startActivity(intent);

            }
        });



//        COS.getInstance().getSts();

        uploadCos.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MediaUtils mediaUtils = new MediaUtils();
                mediaUtils.pickMultiplePicture(v.getContext(), new ArrayList<>(), 10, new IPictureSelectResultListener() {
                    @Override
                    public void onResult(ArrayList<LocalMedia> result) {
                        if (!result.isEmpty()) {
                            String realPath = result.get(0).getRealPath();
                            String fileName = result.get(0).getFileName();

                        }
                    }
                });
            }
        });


        fragment = new ScanCodeDialogFragment(this,new IScanCodeListener() {
            @Override
            public void onResult(String s) {

            }
        });

        scanDialog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                fragment.show();
            }
        });


        scan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity2.this, ScanCodeActivity.class);
                startActivity(intent);
            }
        });

        LogUtils.e("initView");

        LogUtils.d(DeviceUtils.sHA1(this));

        map.setOnClickListener(v -> {
            Intent intent = new Intent(MainActivity2.this, LocationMapActivity.class);
            startActivity(intent);
        });

        one_marker.setOnClickListener(v -> {
            Intent intent = new Intent(MainActivity2.this, OneMarkerLocation.class);
            startActivity(intent);
        });


        getOneLocation.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    LocationUtil.getOneLocation(v.getContext(), new LocationListener() {
                        @Override
                        public void onResult(LocationMode locationMode) {
                            ToastUtils.showShort(locationMode.longitude+","+locationMode.latitude);
                        }

                        @Override
                        public void onError(String e) {
                            ToastUtils.showShort(e);
                        }
                    });
                } catch (Exception e) {
                    e.printStackTrace();
                    ToastUtils.showShort(e.getMessage());
                }
            }
        });


        getAllLocation.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    LocationUtil.getContinueLocation(v.getContext(),1000, new LocationListener() {
                        @Override
                        public void onResult(LocationMode locationMode) {
                            ToastUtils.showShort(locationMode.longitude+","+locationMode.latitude);
                        }

                        @Override
                        public void onError(String e) {
                            ToastUtils.showShort(e);
                        }
                    });
                } catch (Exception e) {
                    e.printStackTrace();
                    ToastUtils.showShort(e.getMessage());
                }
            }
        });


        tree.setOnClickListener(v -> textTree());
        tree2.setOnClickListener(v -> textTree2());

        BaseRecycler<String> baseRecycler = findViewById(R.id.activity_main_test1);
        Button addB = findViewById(R.id.activity_main_test2);
        Button addB2 = findViewById(R.id.activity_main_test3);


        List<String> ddd = new ArrayList<>();
        ddd.add("测试1");
        ddd.add("测试2");


        baseRecycler.setAdapter(ddd,new TestRecyclerAdapter(ddd));
        LogUtils.d(" 替换数据onClick: " + ddd.hashCode());
        addB2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                baseRecycler.clearDataAll();
            }
        });

        List<String> dddff = new ArrayList<>();
        dddff.addAll(ddd);


        setTopBarColor(R.color.purple_200);

        addB.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                jump(TestCreateFormActivity.class);
//                testFormModelMergeJavaBean.getT();
//                baseRecycler.addDatas(dddff);
            }
        });

        selectPerson.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                List<UserMode> userModeList = new ArrayList<>();
                for (int i = 0; i < 10; i++) {
                    UserMode userMode = new UserMode();
                    userMode.id = i+10;
                    userMode.name = "驰珺" + 12 + i;
                    userModeList.add(userMode);
                }

//                SelectUserDialog selectUserDialog = new SelectUserDialog(v.getContext(),userModeList,new ArrayList<>());
//                selectUserDialog.show();

                OnlySelectUserDialog dialog = new OnlySelectUserDialog(v.getContext(), userModeList, new ArrayList<>(), new ISelectUserListener() {
                    @Override
                    public void add(long userId, UserMode userMode) {
                        LogUtils.d(userId  +"--" + userMode.toString());
                    }

                    @Override
                    public void delete(long userId, UserMode userMode) {
                        LogUtils.d(userId  +"--" + userMode.toString());
                    }
                });
                dialog.show();
            }
        });
    }


    private List<MLocalMedia> getTextImage(){
        List<MLocalMedia> myImages = new ArrayList<>();
        MLocalMedia image = new MLocalMedia();
        image.imageType = 1;
        image.urlPath = "https://form-icon-1302729481.cos.ap-beijing.myqcloud.com/icon_1.png";
        myImages.add(image);
        MLocalMedia image1 = new MLocalMedia();
        image1.imageType = 1;
        image1.urlPath = "https://form-icon-1302729481.cos.ap-beijing.myqcloud.com/icon_1.png";
        myImages.add(image1);
        return myImages;
    }

    private void textTree2() {
        List<TreeMode> treeModeLists = new ArrayList<>();
        List<TreeMode> userModeList = new ArrayList<>();
        String[] buMen = new String[]{"市场部333333333","研发部","财务部","人事部","行政部","销售部","客服部","后勤部","企划部","设计部","技术部","运营部","公关部",
                "采购部","质检部","法务部","项目部","培训部"};
        for (int i = 0; i < buMen.length; i++) {
            TreeMode treeMode = new TreeMode("985869596555749" + i,null,buMen[i],TreeMode.DATA_TYPE_MU_LU,i);
            treeModeLists.add(treeMode);
        }
        TreeMode treeMode = new TreeMode("98586959612758" ,"9858695965557490","测试部门13333",TreeMode.DATA_TYPE_MU_LU);
        treeModeLists.add(treeMode);
        TreeMode treeMode1 = new TreeMode("985869596128" ,"9858695965557491","测试部门2",TreeMode.DATA_TYPE_MU_LU);
        treeModeLists.add(treeMode1);


        String[] user = new String[] {
                "曹驰珺","陆璃音","顾浅宁","许沐晨","叶吟萧","秦澜悦","萧槿悠","沈逸弦","傅凝霜","白梓澜","安素锦","贺熙羽","薛念瑶","程楚云","黄梓润",
                "莫云彻","卓婉兮","俞景澜","姜逸尘","陶星澜","余诗婉","宁悦萱","凌楚歌","钟灵犀","常书韵","韦宇澄","邹念薇","潘皓羽","邓雨薇","洪墨羽",
                "冯若琳","董子衿","邵灵犀","程梓萱","黄俊逸","袁芷兰","卢星辰","蔡婉清","覃知许","谢靖琪","苗以沫","石洛尘","叶晓冉","吕苏漾","傅静姝",
                "曾远航","孔可昕","潘言蹊","袁慕辰","丁语嫣","温锦书","邹皓阳","廖雅颂","何雨泽","梁安然","邓羽裳","韦思齐","常少轩","潘婉如","邹明哲",
                "蔡悦兮","洪逸飞","冯芷若","董宇轩","邵晴柔","程梓琪","黄梓榆","袁慕晴","卢锦兮","蔡晨逸","覃若兮","谢知韵","苗楚枫","石雨桐","叶灵均",
                "吕云舒","傅梓航","曾睿思","孔婉婉","潘皓云","袁悦然","丁锦华","温思睿","邹芷若","廖梓铭","何睿泽","梁悦心","邓楚云","韦梓润","常雅琴",
                "潘逸凡","邹思远","蔡芷若","洪锦泽","冯晓萱","董悦悦","邵逸轩","程婉宁","黄子墨","袁睿博","卢楚云","蔡梓萱","覃雅萱","谢逸尘","苗思怡",
                "石芷若","叶锦阳","邹晓羽","廖悦心","何逸凡","梁婉如","邓子墨","韦睿泽","常楚云","潘梓润","蒋雅琴","彭逸尘","邹思远","袁芷若","丁锦阳",
                "段晓羽","石悦心","韦逸凡","常婉如","吕子墨","冯睿泽","程楚云","黄梓润","蒋雅琴","彭逸尘","邹思远","袁芷若","丁锦阳","段晓羽","石悦心",
                "韦逸凡","常婉如","吕子墨","冯睿泽","程楚云","黄梓润","蒋雅琴","彭逸尘","邹思远","袁芷若","丁锦阳","段晓羽","石悦心","韦逸凡","常婉如",
                "吕子墨","冯睿泽","程楚云","黄梓润","蒋雅琴","彭逸尘","邹思远","袁芷若","丁锦阳","段晓羽","石悦心","韦逸凡","常婉如","吕子墨","冯睿泽",
                "程楚云","黄梓润","蒋雅琴","彭逸尘","邹思远","袁芷若","丁锦阳","段晓羽","石悦心","韦逸凡","常婉如","吕子墨","冯睿泽","程楚云","黄梓润",
                "蒋雅琴","彭逸尘","邹思远","袁芷若","丁锦阳","段晓羽","石悦心","韦逸凡","常婉如","吕子墨","冯睿泽","程楚云","黄梓润","蒋雅琴","彭逸尘",
                "邹思远","袁芷若","丁锦阳","段晓羽","石悦心","韦逸凡","常婉如","吕子墨","冯睿泽","程楚云","黄梓润","蒋雅琴","彭逸尘","邹思远","袁芷若",
                "丁锦阳","段晓羽","石悦心","韦逸凡","常婉如","吕子墨","冯睿泽","程楚云","黄梓润","蒋雅琴","彭逸尘","邹思远","袁芷若","丁锦阳","段晓羽",
                "石悦心","韦逸凡","常婉如","吕子墨","冯睿泽","程楚云","黄梓润","蒋雅琴","彭逸尘","邹思远","袁芷若","丁锦阳","段晓羽","石悦心","韦逸凡",
                "常婉如","吕子墨","冯睿泽","程楚云","黄梓润","蒋雅琴","彭逸尘","邹思远","袁芷若","丁锦阳","段晓羽","石悦心","韦逸凡","常婉如","吕子墨",
                "冯睿泽","程楚云","黄梓润","蒋雅琴","彭逸尘","邹思远","袁芷若","丁锦阳","段晓羽","石悦心","韦逸凡","常婉如","吕子墨","冯睿泽","程楚云",
                "黄梓润","蒋雅琴","彭逸尘","邹思远","袁芷若","丁锦阳","段晓羽","石悦心","韦逸凡","常婉如","吕子墨","冯睿泽","程楚云","黄梓润","蒋雅琴",
                "彭逸尘","邹思远","袁芷若","丁锦阳","段晓羽","石悦心","韦逸凡","常婉如","吕子墨","冯睿泽"};
        for (int i = 0; i < user.length; i++) {
            int rangeNumber = NumberUtils.getRangeNumber(treeModeLists.size() - 1, 0);
            String pMuLu = treeModeLists.get(rangeNumber).dataId;
            TreeMode treeMode3 = new TreeMode("985869596555" + i,pMuLu,user[i],TreeMode.DATA_TYPE_DATA,i);
            userModeList.add(treeMode3);
        }
        treeModeLists.addAll(userModeList);

        TreeStructure2 treeStructure2 = findViewById(R.id.activity_main_test_tree4);
        treeStructure2.setData(treeModeLists);

    }

    @Override
    public int initContentView() {
        LogUtils.e("initContentView");
        showTopBar("测试");
        return R.layout.activity_main;
    }

    @Override
    public void doBusiness() {
//        setZhuangTaiLanColor(R.color.purple_200);
    }


    private void textTree(){
        List<TreeMode> treeModeLists = new ArrayList<>();
        List<TreeMode> userModeList = new ArrayList<>();
        String[] buMen = new String[]{"市场部","研发部","财务部","人事部","行政部","销售部","客服部","后勤部","企划部","设计部","技术部","运营部","公关部",
                "采购部","质检部","法务部","项目部","培训部"};
        for (int i = 0; i < buMen.length; i++) {
            TreeMode treeMode = new TreeMode("985869596555749" + i,null,buMen[i],TreeMode.DATA_TYPE_MU_LU);
            treeModeLists.add(treeMode);
        }
        String[] user = new String[] {
                "曹驰珺","陆璃音","顾浅宁","许沐晨","叶吟萧","秦澜悦","萧槿悠","沈逸弦","傅凝霜","白梓澜","安素锦","贺熙羽","薛念瑶","程楚云","黄梓润",
                "莫云彻","卓婉兮","俞景澜","姜逸尘","陶星澜","余诗婉","宁悦萱","凌楚歌","钟灵犀","常书韵","韦宇澄","邹念薇","潘皓羽","邓雨薇","洪墨羽",
                "冯若琳","董子衿","邵灵犀","程梓萱","黄俊逸","袁芷兰","卢星辰","蔡婉清","覃知许","谢靖琪","苗以沫","石洛尘","叶晓冉","吕苏漾","傅静姝",
                "曾远航","孔可昕","潘言蹊","袁慕辰","丁语嫣","温锦书","邹皓阳","廖雅颂","何雨泽","梁安然","邓羽裳","韦思齐","常少轩","潘婉如","邹明哲",
                "蔡悦兮","洪逸飞","冯芷若","董宇轩","邵晴柔","程梓琪","黄梓榆","袁慕晴","卢锦兮","蔡晨逸","覃若兮","谢知韵","苗楚枫","石雨桐","叶灵均",
                "吕云舒","傅梓航","曾睿思","孔婉婉","潘皓云","袁悦然","丁锦华","温思睿","邹芷若","廖梓铭","何睿泽","梁悦心","邓楚云","韦梓润","常雅琴",
                "潘逸凡","邹思远","蔡芷若","洪锦泽","冯晓萱","董悦悦","邵逸轩","程婉宁","黄子墨","袁睿博","卢楚云","蔡梓萱","覃雅萱","谢逸尘","苗思怡",
                "石芷若","叶锦阳","邹晓羽","廖悦心","何逸凡","梁婉如","邓子墨","韦睿泽","常楚云","潘梓润","蒋雅琴","彭逸尘","邹思远","袁芷若","丁锦阳",
                "段晓羽","石悦心","韦逸凡","常婉如","吕子墨","冯睿泽","程楚云","黄梓润","蒋雅琴","彭逸尘","邹思远","袁芷若","丁锦阳","段晓羽","石悦心",
                "韦逸凡","常婉如","吕子墨","冯睿泽","程楚云","黄梓润","蒋雅琴","彭逸尘","邹思远","袁芷若","丁锦阳","段晓羽","石悦心","韦逸凡","常婉如",
                "吕子墨","冯睿泽","程楚云","黄梓润","蒋雅琴","彭逸尘","邹思远","袁芷若","丁锦阳","段晓羽","石悦心","韦逸凡","常婉如","吕子墨","冯睿泽",
                "程楚云","黄梓润","蒋雅琴","彭逸尘","邹思远","袁芷若","丁锦阳","段晓羽","石悦心","韦逸凡","常婉如","吕子墨","冯睿泽","程楚云","黄梓润",
                "蒋雅琴","彭逸尘","邹思远","袁芷若","丁锦阳","段晓羽","石悦心","韦逸凡","常婉如","吕子墨","冯睿泽","程楚云","黄梓润","蒋雅琴","彭逸尘",
                "邹思远","袁芷若","丁锦阳","段晓羽","石悦心","韦逸凡","常婉如","吕子墨","冯睿泽","程楚云","黄梓润","蒋雅琴","彭逸尘","邹思远","袁芷若",
                "丁锦阳","段晓羽","石悦心","韦逸凡","常婉如","吕子墨","冯睿泽","程楚云","黄梓润","蒋雅琴","彭逸尘","邹思远","袁芷若","丁锦阳","段晓羽",
                "石悦心","韦逸凡","常婉如","吕子墨","冯睿泽","程楚云","黄梓润","蒋雅琴","彭逸尘","邹思远","袁芷若","丁锦阳","段晓羽","石悦心","韦逸凡",
                "常婉如","吕子墨","冯睿泽","程楚云","黄梓润","蒋雅琴","彭逸尘","邹思远","袁芷若","丁锦阳","段晓羽","石悦心","韦逸凡","常婉如","吕子墨",
                "冯睿泽","程楚云","黄梓润","蒋雅琴","彭逸尘","邹思远","袁芷若","丁锦阳","段晓羽","石悦心","韦逸凡","常婉如","吕子墨","冯睿泽","程楚云",
                "黄梓润","蒋雅琴","彭逸尘","邹思远","袁芷若","丁锦阳","段晓羽","石悦心","韦逸凡","常婉如","吕子墨","冯睿泽","程楚云","黄梓润","蒋雅琴",
                "彭逸尘","邹思远","袁芷若","丁锦阳","段晓羽","石悦心","韦逸凡","常婉如","吕子墨","冯睿泽"};
        for (int i = 0; i < user.length; i++) {
            int rangeNumber = NumberUtils.getRangeNumber(treeModeLists.size() - 1, 0);
            String pMuLu = treeModeLists.get(rangeNumber).dataId;
            TreeMode treeMode = new TreeMode("985869596555" + i,pMuLu,user[i],TreeMode.DATA_TYPE_DATA);
            userModeList.add(treeMode);
        }
        treeModeLists.addAll(userModeList);

        TreeView treeView = findViewById(R.id.activity_main_test_tree2);
        treeView.setTitleName("测试目录")
                .setShowLevel(2) // 显示级别
                .setOnlyShowMuLu(false) //初始加载是否只显示目录
                .setSuoJinJiBie(3)//缩进级别
                .setDataDefaultImageResource(com.example.ccj.R.mipmap.bar_code)//数据默认图标
                .setMuLuDefaultImageResource(com.example.ccj.R.mipmap.drawing_boar_brush_gray)//目录默认图标
                .setData(treeModeLists)//数据
                //选中或取消选中回调
                .setSelectTreeListener(new ISelectTreeListener() {
                    @Override
                    public void select(TreeMode treeMode) {
                        //选中回调
                    }

                    @Override
                    public void delete(TreeMode treeMode) {
                        //取消选中回调
                    }
                })
                .show();//绘制
    }

    @Override
    public void onPermissionGranted(int requestCode) {
        super.onPermissionGranted(requestCode);
        LogUtils.e("获取到权限：" +requestCode);
    }
}